package com.appwoo.txtws.activity;

import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.res.Resources;
import android.os.AsyncTask;
import android.os.Bundle;
import android.text.Editable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemLongClickListener;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.TextView;
import com.appwoo.android.exception.NotFoundNetWorkException;
import com.appwoo.android.exception.TimeOutException;
import com.appwoo.txtws.adapter.QQPhonesAdapter;
import com.appwoo.txtws.app.AppActivity;
import com.appwoo.txtws.bean.PhoneBean;
import com.appwoo.txtws.bean.StateBean;
import com.appwoo.txtws.component.Global;
import com.appwoo.txtws.component.RqSP;
import com.appwoo.txtws.service.LoginService;
import com.appwoo.txtws.service.RQFamilyPhone;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.xmlpull.v1.XmlPullParserException;

public class QQPhoneActivity extends AppActivity
  implements View.OnClickListener
{
  private ArrayList<PhoneBean> addPhoneList = null;
  private ArrayList<PhoneBean> delPhoneList = null;
  private EditText dialog_addphone_telnum;
  private EditText dialog_addphone_username;
  private QQPhonesAdapter fAdapter = null;
  private List<PhoneBean> f_phoneList = null;
  private ListView listView_phones;
  private RQFamilyPhone rqPhone = null;
  private TextView textview_phones_action;
  private TextView tv_qqphone_no;
  private TextView tv_qqphone_yes;
  private String userId = "";
  private ProgressDialog v_progressDialog;

  private void addItemListener()
  {
    this.listView_phones.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener()
    {
      public boolean onItemLongClick(AdapterView<?> paramAnonymousAdapterView, View paramAnonymousView, int paramAnonymousInt, long paramAnonymousLong)
      {
        PhoneBean localPhoneBean = (PhoneBean)paramAnonymousAdapterView.getItemAtPosition(paramAnonymousInt);
        if (localPhoneBean.getType().equals("0"))
          QQPhoneActivity.this.delPhone(QQPhoneActivity.this, localPhoneBean);
        while (true)
        {
          return false;
          AlertDialog.Builder localBuilder = new AlertDialog.Builder(QQPhoneActivity.this);
          localBuilder.setTitle(QQPhoneActivity.this.getString(2131427740));
          localBuilder.setMessage(QQPhoneActivity.this.getString(2131427798));
          localBuilder.setPositiveButton(QQPhoneActivity.this.getString(2131427513), null);
          localBuilder.show();
        }
      }
    });
  }

  private void addListener()
  {
    this.textview_phones_action.setOnClickListener(this);
    addItemListener();
  }

  private void addPhoneDialog(Context paramContext)
  {
    View localView = LayoutInflater.from(paramContext).inflate(2130903090, null);
    dialogViewInit(localView);
    final Dialog localDialog = new Dialog(paramContext, 2131361814);
    localDialog.setContentView(localView);
    this.tv_qqphone_yes.setOnClickListener(new View.OnClickListener()
    {
      public void onClick(View paramAnonymousView)
      {
        String str1 = QQPhoneActivity.this.dialog_addphone_telnum.getText().toString();
        String str2 = QQPhoneActivity.this.dialog_addphone_username.getText().toString();
        String str3 = Global.getDateAndTime(QQPhoneActivity.this);
        if (!str1.equals(""))
        {
          if (!str2.equals(""))
          {
            int i = 0;
            while (true)
            {
              int j = QQPhoneActivity.this.f_phoneList.size();
              int k = 0;
              if (i >= j)
                label86: if (k == 0)
                {
                  QQPhoneActivity.this.addPhoneList.clear();
                  PhoneBean localPhoneBean = new PhoneBean();
                  localPhoneBean.setPno(str1);
                  localPhoneBean.setPname(str2);
                  localPhoneBean.setPtype("亲情");
                  localPhoneBean.setUdtime(str3);
                  localPhoneBean.setIsdel("0");
                  QQPhoneActivity.this.addPhoneList.add(localPhoneBean);
                  new QQPhoneActivity.PhoneAsyncTask(QQPhoneActivity.this).execute(new String[] { "add" });
                }
              else
                try
                {
                  localDialog.dismiss();
                  return;
                  if ((str1.equals(((PhoneBean)QQPhoneActivity.this.f_phoneList.get(i)).getPno())) && (((PhoneBean)QQPhoneActivity.this.f_phoneList.get(i)).getIsdel().equals("0")))
                  {
                    k = 1;
                    break label86;
                  }
                  i++;
                }
                catch (Exception localException)
                {
                  localException.printStackTrace();
                  return;
                }
            }
            QQPhoneActivity.this.alertMessage(QQPhoneActivity.this.getString(2131427792));
            return;
          }
          QQPhoneActivity.this.alertMessage(QQPhoneActivity.this.getString(2131427791));
          return;
        }
        QQPhoneActivity.this.alertMessage(QQPhoneActivity.this.getString(2131427793));
      }
    });
    this.tv_qqphone_no.setOnClickListener(new View.OnClickListener()
    {
      public void onClick(View paramAnonymousView)
      {
        try
        {
          localDialog.dismiss();
          return;
        }
        catch (Exception localException)
        {
          localException.printStackTrace();
        }
      }
    });
    localDialog.show();
  }

  private String bgAddPhone(ArrayList<PhoneBean> paramArrayList)
  {
    StateBean localStateBean = this.rqPhone.addPhones(paramArrayList, this.userId);
    if (localStateBean != null)
    {
      if (localStateBean.getCode().equals("0"))
        return "0";
      return localStateBean.getDesc();
    }
    return getString(2131427771);
  }

  private String bgDelPhone(ArrayList<PhoneBean> paramArrayList)
  {
    StateBean localStateBean = this.rqPhone.delPhones(paramArrayList, this.userId);
    if (localStateBean != null)
    {
      if (localStateBean.getCode().equals("0"))
        return "0";
      return localStateBean.getDesc();
    }
    return getString(2131427771);
  }

  private String bgInitList()
  {
    try
    {
      this.f_phoneList = new LoginService().getPhoneList(this.userId, "1900-01-01 00:00:00", this);
      return "";
    }
    catch (IOException localIOException)
    {
      return getString(2131427525);
    }
    catch (XmlPullParserException localXmlPullParserException)
    {
      return getString(2131427525);
    }
    catch (TimeOutException localTimeOutException)
    {
      return getString(2131427525);
    }
    catch (NotFoundNetWorkException localNotFoundNetWorkException)
    {
      localNotFoundNetWorkException.getClass();
    }
    return "没有连接到网络";
  }

  private void bgShowAll(String paramString)
  {
    if (this.f_phoneList == null)
    {
      alertMessage(paramString);
      return;
    }
    if (this.f_phoneList.size() == 0)
    {
      alertMessage(getString(2131427788));
      return;
    }
    this.listView_phones.setAdapter(getAlreadyAdapter(dealWithList(this.f_phoneList)));
  }

  private void createOrShowDialog()
  {
    if ((this.v_progressDialog == null) || (!this.v_progressDialog.isShowing()))
    {
      this.v_progressDialog = new ProgressDialog(this);
      this.v_progressDialog.setMessage(getString(2131427516));
      this.v_progressDialog.setCancelable(true);
      if (!this.v_progressDialog.isShowing())
        this.v_progressDialog.show();
    }
  }

  private ArrayList<PhoneBean> dealWithList(List<PhoneBean> paramList)
  {
    int i = paramList.size();
    ArrayList localArrayList = new ArrayList();
    for (int j = 0; ; j++)
    {
      if (j >= i)
        return localArrayList;
      PhoneBean localPhoneBean = (PhoneBean)paramList.get(j);
      if (localPhoneBean.getIsdel().equals("0"))
        localArrayList.add(localPhoneBean);
    }
  }

  private void delPhone(Context paramContext, final PhoneBean paramPhoneBean)
  {
    AlertDialog.Builder localBuilder = new AlertDialog.Builder(paramContext);
    localBuilder.setIcon(2130837508);
    localBuilder.setTitle(getString(2131427522));
    localBuilder.setMessage(getString(2131427523) + "：" + paramPhoneBean.getPno() + "？");
    localBuilder.setPositiveButton(getString(2131427513), new DialogInterface.OnClickListener()
    {
      public void onClick(DialogInterface paramAnonymousDialogInterface, int paramAnonymousInt)
      {
        QQPhoneActivity.this.delPhoneList.clear();
        QQPhoneActivity.this.delPhoneList.add(paramPhoneBean);
        new QQPhoneActivity.PhoneAsyncTask(QQPhoneActivity.this).execute(new String[] { "del" });
      }
    });
    localBuilder.setNegativeButton(getString(2131427514), null);
    localBuilder.create().show();
  }

  private void dialogViewInit(View paramView)
  {
    this.dialog_addphone_telnum = ((EditText)paramView.findViewById(2131493085));
    this.dialog_addphone_username = ((EditText)paramView.findViewById(2131493086));
    this.tv_qqphone_yes = ((TextView)paramView.findViewById(2131493087));
    this.tv_qqphone_no = ((TextView)paramView.findViewById(2131493088));
  }

  private QQPhonesAdapter getAlreadyAdapter(List<PhoneBean> paramList)
  {
    if (paramList != null);
    try
    {
      this.fAdapter = new QQPhonesAdapter(this, paramList);
      this.fAdapter.notifyDataSetChanged();
      label24: return this.fAdapter;
    }
    catch (Exception localException)
    {
      break label24;
    }
  }

  private void init()
  {
    this.addPhoneList = new ArrayList();
    this.delPhoneList = new ArrayList();
    this.rqPhone = new RQFamilyPhone(this);
    this.textview_phones_action = ((TextView)findViewById(2131493362));
    this.listView_phones = ((ListView)findViewById(2131493361));
    this.userId = new RqSP().getLgDevAccount(this);
  }

  private void initActionBar()
  {
    hideBarHome();
    setBarTitle(getResources().getString(2131427620));
    setBarBackOnClickListener(new View.OnClickListener()
    {
      public void onClick(View paramAnonymousView)
      {
        QQPhoneActivity.this.finish();
      }
    });
  }

  private void postAddPhone(String paramString)
  {
    if (paramString.equals("0"))
    {
      alertMessage(getString(2131427520));
      showPhoneList();
    }
    while (true)
    {
      this.addPhoneList.clear();
      return;
      alertMessage(paramString);
    }
  }

  private void postDelPhone(String paramString)
  {
    if (paramString.equals("0"))
    {
      alertMessage(getString(2131427517));
      showPhoneList();
    }
    while (true)
    {
      this.delPhoneList.clear();
      return;
      alertMessage(paramString);
    }
  }

  private void showPhoneList()
  {
    new PhoneAsyncTask().execute(new String[] { "init" });
  }

  protected void backKeyCallBack()
  {
    super.backKeyCallBack();
    finish();
  }

  public void onBackPressed()
  {
    super.onBackPressed();
    finish();
  }

  public void onClick(View paramView)
  {
    switch (paramView.getId())
    {
    default:
      return;
    case 2131493362:
    }
    addPhoneDialog(this);
  }

  protected void onCreate(Bundle paramBundle)
  {
    super.onCreate(paramBundle);
    setContentView(2130903175);
    init();
    initActionBar();
    addListener();
    showPhoneList();
  }

  public class PhoneAsyncTask extends AsyncTask<String, Integer, String>
  {
    private String method = "";

    public PhoneAsyncTask()
    {
    }

    protected String doInBackground(String[] paramArrayOfString)
    {
      this.method = paramArrayOfString[0];
      if (this.method.equals("init"))
        return QQPhoneActivity.this.bgInitList();
      if (this.method.equals("add"))
        return QQPhoneActivity.this.bgAddPhone(QQPhoneActivity.this.addPhoneList);
      if (this.method.equals("del"))
        return QQPhoneActivity.this.bgDelPhone(QQPhoneActivity.this.delPhoneList);
      return "";
    }

    protected void onPostExecute(String paramString)
    {
      if (this.method.equals("init"))
        if (paramString != null)
          QQPhoneActivity.this.bgShowAll(paramString);
      try
      {
        while (true)
        {
          QQPhoneActivity.this.v_progressDialog.dismiss();
          return;
          if (this.method.equals("add"))
            QQPhoneActivity.this.postAddPhone(paramString);
          else if (this.method.equals("del"))
            QQPhoneActivity.this.postDelPhone(paramString);
        }
      }
      catch (Exception localException)
      {
      }
    }

    protected void onPreExecute()
    {
      QQPhoneActivity.this.createOrShowDialog();
    }
  }
}

/* Location:           C:\Documents and Settings\Administrator\classes_dex2jar.jar
 * Qualified Name:     com.appwoo.txtws.activity.QQPhoneActivity
 * JD-Core Version:    0.6.2
 */